﻿$(document).ready(function () {
    /* 表弹验证
    --------------------------------------------------*/
    if ($('#Validform').length > 0) {
        $("#Validform").Validform({
            ajaxPost: true,
            datatype: {//传入自定义datatype类型
                "zdata": /^[1-9]?\d{1}(\.\d+)?$/,
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
                //大于0的整数
                "zzzs": /^[1-9]\d{0,}$/,
                //大于0的数
                "zs": /^[ + ]?(0\.\d+)|([1-9][0-9]*(\.\d+)?)$/,
            },
            callback: function (data) {
                if (data.url != 'no') {
                    $.Showmsg(data.Message + ' 马上跳转...');
                } else {
                    $.Showmsg(data.Message);
                }
                setTimeout(function () {
                    $.Hidemsg();
                    if (data.url != 'no') {
                        location = data.url;
                    }
                }, 2000);
            }
        });
    }

    if ($('#Validform1').length > 0) {
        $("#Validform1").Validform({
            ajaxPost: true,
            datatype: {//传入自定义datatype类型
                "zdata": /^[1-9]?\d{1}(\.\d+)?$/,
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
                //大于0的整数
                "zzzs": /^[1-9]\d{0,}$/,
                //大于0的数
                "zs": /^[ + ]?(0\.\d+)|([1-9][0-9]*(\.\d+)?)$/
            },
            callback: function (data) {
                if (data.url != 'no') {
                    $.Showmsg(data.Message + ' 马上跳转...');
                } else {
                    $.Showmsg(data.Message);
                }
                setTimeout(function () {
                    $.Hidemsg();
                    if (data.url != 'no') {
                        location = data.url;
                    }
                }, 2000);
            }
        });
    }

    if ($('#fileValid').length > 0) {
        $("#fileValid").Validform({
            ajaxPost: true,
            beforeSubmit: function (curform) {
                curform.ajaxSubmit({
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data.state) {
                            parent.$('#headimg').attr('src', data.Message);
                            parent.$('#head').val(data.url);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            $.Showmsg(data.Message);
                        }
                    }
                });
                return false;
            }
        });
    }

    if ($('#excelValid').length > 0) {
        $("#excelValid").Validform({
            ajaxPost: true,
            beforeSubmit: function (curform) {
                curform.ajaxSubmit({
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        //data = $.parseJSON($(data).text());
                        if (data.state) {
                            parent.$.Showmsg(data.Message);
                            parent.getList();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                        else {
                            $.Showmsg(data.Message);
                        }
                    }
                });
                return false;
            }
        });
    }

    if ($('#giveupValid').length > 0) {
        $("#giveupValid").Validform({
            ajaxPost: true,
            callback: function (data) {
                $.Hidemsg();
                if (data.Message == "-1") {
                    $.Showmsg('系统错误！');
                }
                else if (data.Message == "0.0") {
                    layer.confirm('本轮招聘中，您本次放弃该岗位后只有一次重新选择岗位的机会。是否确认放弃该岗位？', {
                        btn: ['决定放弃', '不放弃']
                    }, function () {
                        $('input[name=state]').val('ok');
                        layer.closeAll();
                        $('#giveupValid').submit();
                    }, function () {
                        //不放弃
                    });
                } else if (data.Message == "1.0") {
                    layer.confirm('本轮招聘中，您之前已经重新选择岗位，如再次放弃该岗位，则表示自愿放弃本次应聘！是否确认放弃该岗位？', {
                        btn: ['决定放弃', '不放弃']
                    }, function () {
                        $('input[name=state]').val('ok');
                        layer.closeAll();
                        $('#giveupValid').submit();
                    }, function () {
                        //不放弃
                    });
                } else {
                    $.Showmsg(data.Message);
                    setTimeout(function () {
                        $.Hidemsg();
                        if (data.state) {
                            location.reload();
                        }
                    }, 2000);
                }
            }
        });
    }

});

//打开窗口页面
function openLayer(title, url, width, height) {
    layer.open({
        type: 2,
        title: title,
        shade: 0.5,
        area: [width, height],
        content: encodeURI(url)
    });
}

function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'get',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}

function postAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "json",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}

//页面样式渲染
function setWidth() {
    $('select').each(function () {
        var sid=$(this).attr("id");
        if(sid!='province'&&sid!='city' && sid!='area'&&sid!='street'){
            $(this).css('width', $(this).parent().width() - 5);
        }
    });
    $('textarea').each(function () {
        $(this).css('width', $(this).parent().width() - 17);
    });
    $('input[type=text]').each(function () {
        if($(this).attr("id")!='txt_street'){
        $(this).css('width', $(this).parent().width() - parseFloat($(this).css("padding-left").replace('px', '')) - parseFloat($(this).css("padding-right").replace('px', '')) - 7);
        }
    });
}

//页面加载完成后关闭进度条
function initView() {
    setTimeout(function () {
        $('#loader').hide();
    }, 200);
}

//滚动的时候固定到浏览器顶部
function fixDiv(id) {
    var obj = $("#" + id);
    //导航距离屏幕顶部距离 
    var _defautlTop = 400;
    //导航距离屏幕左侧距离 
    var _defautlLeft = obj.offset().left - $(window).scrollLeft();
    //导航默认样式记录，还原初始样式时候需要 
    var _position = obj.css('position');
    var _top = obj.css('top');
    var _left = obj.css('left');
    var _zIndex = obj.css('z-index');
    setLocation(obj, _defautlTop, _defautlLeft, _position, _top, _left, _zIndex);
    //鼠标滚动事件 
    $(window).scroll(function () {
        setLocation(obj, _defautlTop, _defautlLeft, _position, _top, _left, _zIndex);
    });
}

function setLocation(obj, _defautlTop, _defautlLeft, _position, _top, _left, _zIndex) {
    if ($(this).scrollTop() > _defautlTop) {
        //IE6不认识position:fixed，单独用position:absolute模拟 
        if ('undefined' == typeof(document.body.style.maxHeight)) {
            obj.css({
                'position': 'absolute',
                'top': eval(document.documentElement.scrollTop),
                'left': _defautlLeft,
                'z-index': 99999
            });
            //防止出现抖动 
            $("html,body").css({'background-image': 'url(about:blank)', 'background-attachment': 'fixed'});
        } else {
            obj.css({'position': 'fixed', 'top': 0, 'left': _defautlLeft, 'z-index': 999, 'padding-top': '0'});
        }
    } else {
        obj.css({'position': _position, 'top': _top, 'left': _left, 'z-index': _zIndex, 'padding-top': '0'});
    }
}
